#!/usr/bin/python
import os;
class Download:
	def __init__(self,url,downloadname):
		self.video_url=url;
		self.format=[100,22,18,34,5];
		self.video_name=downloadname;
		self.file_extend={"22":".mp4","18":".mp4","34":".flv","5":".flv","100":".mp4"}


	def download_file(self):
		r  =0;
		for f in self.format:
			cmd ="./youtube-dl";
			cmd +=" -f "	+str(f);
			cmd +=" "	+self.video_url;
			cmd +=" -r "	+"1m"
			cmd +=" -o "	+ self.video_name+self.file_extend[str(f)];
			re  = os.system(cmd);
			#re = 1;
			if (re == 0):
				print "succ " + cmd;
				return 0;
			else:
				print "fail " + cmd;
		print "fail all: "+self.video_url;
		return -1;	


download=Download("http://www.youtube.com/watch?v=-D7uILB3GkQ","output/11");
print download.download_file();
print download.video_url;
#d= os.system('lx -lh')
#if d == 0 :

#print d
